#include "HdmiOutputSource.h"
#include "Util/logc.h"

namespace Media{

    HdmiOutputSource::HdmiOutputSource():OutputSource(HDMI, VIDEO, "HdmiOutput", false){
        m_vOut = nullptr;
        HdmiOutputSource::Start();
    }
    HdmiOutputSource::~HdmiOutputSource(){
        tracef(" ~HdmiOutputSource");
    }
    bool HdmiOutputSource::Start(){
        if(m_vOut) return true;

        VideoOutDesc desc = {};
        desc.type = videoOutHdmi;
        if(createVideoOutput(&desc, &m_vOut) <0){
            errorf("createVideoOutput  hdmi out  fail");
            return false;
        }
        if(m_vOut && m_vOut->start(m_vOut) == 0) {
            tracef("hdmi out start  ok");
            return true;
        }
        errorf(" hdmi out start  fail");
        return false;
    }
    bool HdmiOutputSource::Stop(){


//        if(m_vOut->stop(m_vOut) == 0) {
//            return true;
//        }

        return true;
    }
    bool HdmiOutputSource::InputPacket(const FrameCommon::Frame::Ptr& frame) {
        
        return false;
    }
    bool HdmiOutputSource::InputFrame(void* frame){
        if(m_vOut && m_vOut->sendFrame(m_vOut, frame) == 0) {
            return true;
        }
        errorf("hdmi out sendFrame fail");
        return false;
    }
    HdmiOutputSource::Ptr HdmiOutputSource::Instance() {
        static auto ptr = std::make_shared<HdmiOutputSource>();
        return ptr;
    }


}